package com.awardsystem.Utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.UUID;

import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.web.multipart.MultipartFile;


public class FileUtils {
        public static void uploadFileByByte(byte[] file, String filePath, String fileName) throws Exception {
            File targetFile = new File(filePath);
            if(!targetFile.exists()){
                targetFile.mkdir();
            }
            FileOutputStream out = new FileOutputStream(filePath+"/"+fileName);
            out.write(file);
            out.flush();
            out.close();
            System.out.println("upload success");
        }

        public static void uploadFileByStream(InputStream inputStream, String filePath, String fileName) throws Exception {
            File targetFile = new File(filePath);
            if(!targetFile.exists()){
                targetFile.mkdir();
            }
            FileOutputStream out = new FileOutputStream(filePath+"/"+fileName);
            IOUtils.copy(inputStream,out);
            out.flush();
            out.close();
            System.out.println("upload success");
        }


}
